home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5649 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: stc06.ctd.ornl.gov!msr!kennel
  2. From: kennel@msr.epm.ornl.gov (Matt Kennel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: External access to private class variables
  5. Date: 6 Feb 1996 03:26:05 GMT
  6. Organization: Oak Ridge National Lab, Oak Ridge, TN
  7. Distribution: world
  8. Message-ID: <4f6hod$3j6@stc06.ctd.ornl.gov>
  9. References: <4ermr9$ii7@cloner2.ix.netcom.com> <ENNO.96Feb2203423@kitz.inferenzsysteme.informatik.th-darmstadt.de> <4eu3n7$rbi@clarknet.clark.net>
  10. NNTP-Posting-Host: msr.epm.ornl.gov
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Harlan Messinger (gusty@clark.net) wrote:
  14.  
  15. > This isn't strange. An object can have several names and be pointed to by 
  16. > several pointers. Making one of those names private hides just that name. 
  17. > It doesn't hide any of the other names, and it doesn't hide the pointers 
  18. > to it.
  19.  
  20. Well, in my opinion it IS really is strange.  Most other OO languages have
  21. references to objects and nothing but.  They may change internal state of
  22. an object only through the class interface. 
  23.  
  24. > Treating your example for the sake of discussion as real code that 
  25. > someone wrote, all this means is that somebody didn't want the name "x" 
  26. > used to access that spot in memory, but wanted it to be called GSValue() 
  27. > instead. Perhaps GSValue() is a meaningful name for the intended user, 
  28. > and the current implementation of GSValue() is via an integer data 
  29. > member, but perhaps later on it will be via some other private mechanism. 
  30. > If that happens, the change will be invisible to the user, who will still 
  31. > use the public member reference function GSValue() just as before.
  32.  
  33. That would be fine, as long as you could only do it as
  34.  
  35.     object.GSValue() = 1777;
  36.  
  37. In this way, I'd still say that you are modifying things by permission of
  38. the class interface.
  39.  
  40. But this GSValue() thing can be stored and flung around separately. 
  41.  
  42. cheers
  43. Matt
  44.